package cn.christ.com.mobilesafe.common.utils;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import cn.christ.com.mobilesafe.MyApp;

/**
 * Created by Christ on 2018/7/13.
 * 应用包的工具
 */

public class PackageUtil {
    private static PackageManager pm;
    private static PackageInfo info;

    /**
     * 静态代码块
     */
    static {
        try {
            pm = MyApp.context.getPackageManager();
            info = pm.getPackageInfo(MyApp.context.getPackageName(), 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获取版本名
     */
    public static String getVersionName() {
        return info.versionName;
    }

    /**
     * 获取版本号
     */
    public static int getVersionCode() {
        return info.versionCode;
    }

}
